var nowPage=1;  //初始化当前页面数；
var p_no;    //每页显示的行数；
var sumForm;
var sumPage;
var submitEnter=0;
function cutPage(){
	if(!localStorage.getItem("first"))
		localStorage.setItem("howLow","4");//默认4行先
	p_no = localStorage.getItem("howLow");
	sumForm = $('form').size(); //统计有多少行数据，以方便分页统计；
	sumPage=Math.ceil(sumForm/p_no);            //算出一共有多少页；向上取整数页；
	$("#tips").text("一共有多少行数据"+sumForm);
	$("#nowPage").text("当前页数: "+nowPage+"/"+sumPage);
	$("table").hide();
	$("table:eq(0)").show();
	showData();
	var h = screen.height;
	$("#container").css("height",h);
}

function showData(){
	
	for(var s=(nowPage-1)*p_no+1;s<=nowPage*p_no;s++)//索引号显示1到2显示形成 一个等差数列
		$('table:eq('+s+')').show();

		
}

$(document).ready(function(){
	$("#next").click(function(){
		nowPage++;
		//var nowPage_forward=nowPage-1;//局部擦除  把上一页给抹去
		//for(var s=(nowPage_forward-1)*p_no+1;s<=nowPage_forward*p_no;s++)
			//$('table:eq('+s+')').hide();
		if(nowPage>=sumPage)
			nowPage=sumPage;
		$("table").hide();
		$("table:eq(0)").show();
		showData();
		$("#nowPage").text("当前页数: "+nowPage+"/"+sumPage);
		
		
	});
	
	$("#forward").click(function(){
		nowPage-=1;
		//var nowPage_next=nowPage+1; //局部擦除  把下一页给抹去  
		//for(var h=(nowPage_next-1)*p_no+1;h<=nowPage_next*p_no;h++)
			//$('table:eq('+h+')').hide();
		if(nowPage<1)
			nowPage=1;
		$("table").hide();
		$("table:eq(0)").show();
		showData();
		$("#nowPage").text("当前页数: "+nowPage+"/"+sumPage);
		
	});
	$("#go").click(function(){
		
		var p = $("#pageValue").val();
		if(p>sumPage||p<=0)
		{
			
			$("#tip").text("老哥，搞事情？？？？？");
			setTimeout(function(){$("#tip").text('');},2500);
			
		}
		else{
		for(var h=(nowPage-1)*p_no+1;h<=nowPage*p_no;h++)//把当前页隐藏起来；
			$('table:eq('+h+')').hide();
		for(var s=(p-1)*p_no+1;s<=p*p_no;s++)//把前进页显示出来；
			$('table:eq('+s+')').show();
			nowPage=p;
			$("#nowPage").text("当前页数: "+nowPage+"/"+sumPage);
		}
	});
	
	$("#age").keyup(function(){              //输入约束-------------------------
		
		var age = $(this).val();
		if(isNaN(age)||age<=5||age>125)
		{	
			$("#tip").text("请重新输入正确的年龄值！");
			$("#submits").attr("type","button");
			setTimeout(function(){ $("#tip").text('')},2000);
		}
		
	});

	$("#submits").click(function(){
		
		
		var email = $("#email").val();
		var emailRegexp=/^(\w)+(\.\w+)*@(\w)+((\.\w{2,3}){1,3})$/;
		if(!emailRegexp.test(email))
			{
				$("#tip").text("大哥大姐，邮箱格式有误！！！");
				$("#submits").attr("type","button");
				
			}
		
		submitEnter=1;
	});
	
	$("#submits").mouseleave(function(){
		if(submitEnter==1)
		{
		 $(this).attr("type","submit");
		setTimeout(function(){ $("#tip").text('')},2000);
		}
		submitEnter=0;
	});
	
	$("#change").click(function(){
		
		var row = $("#howLow").val();
		if(row<=0)	
		{	$("#tip").text("老哥，搞事情？？？？？");
			setTimeout(function(){$("#tip").text('');},2500);
		}
		else{
		localStorage.setItem("howLow",row);
		localStorage.setItem("first","1");
		window.location.reload(true);
		}
	});
	
	
})